cmake_minimum_required(VERSION 3.8)
project(cpp01_topic)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies REQUIRED必须找到 OPTIONAL可选的 
                  #COMPONENTS只需找QT5下的Widgets即可

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(turtlesim REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(base_interfaces_demo)
find_package(Qt5 REQUIRED COMPONENTS Widgets)

#声明可执行程序
add_executable(demo01_str_pub src/demo01_str_pub.cpp)
add_executable(demo02_str_sub src/demo02_str_sub.cpp)
add_executable(demo03_stu_pub src/demo03_stu_pub.cpp)
add_executable(demo04_stu_sub src/demo04_stu_sub.cpp)
add_executable(demo05_turtle_circle_pub src/demo05_turtle_circle_pub.cpp)
add_executable(demo06_turtle_pose_sub src/demo06_turtle_pose_sub.cpp)
add_executable(demo07_turtle_control src/demo07_turtle_control.cpp)
add_executable(demo08_hello_qt src/demo08_hello_qt.cpp)
add_executable(demo09_sys_status_display_sub src/demo09_sys_status_display_sub.cpp)

#声明需要和哪些外部库链接，带<>是库
target_link_libraries(demo08_hello_qt Qt5::Widgets)
target_link_libraries(demo09_sys_status_display_sub Qt5::Widgets)

#声明源文件需要的include文件
target_include_directories(demo01_str_pub PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)


#声明编译特性
target_compile_features(demo01_str_pub PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

#声明可执行目标和依赖
ament_target_dependencies(
  demo01_str_pub
  "rclcpp"
  "std_msgs"
  "base_interfaces_demo"
)

ament_target_dependencies(
  demo02_str_sub
  "rclcpp"
  "std_msgs"
  "base_interfaces_demo"
)
ament_target_dependencies(
  demo03_stu_pub
  "rclcpp"
  "std_msgs"
  "base_interfaces_demo"
)
ament_target_dependencies(
  demo04_stu_sub
  "rclcpp"
  "std_msgs"
  "base_interfaces_demo"
)

ament_target_dependencies(
  demo05_turtle_circle_pub
  "rclcpp"
  "geometry_msgs"
)
ament_target_dependencies(
  demo06_turtle_pose_sub
  "rclcpp"
  "turtlesim"
)
ament_target_dependencies(
  demo07_turtle_control
  "rclcpp"
  "geometry_msgs"
  "turtlesim"
)
ament_target_dependencies(
  demo09_sys_status_display_sub
  "rclcpp" 
  "base_interfaces_demo"
)

#将目标安装到install目录下的lib目录的同名目录中
install(TARGETS 
demo01_str_pub
demo02_str_sub
demo03_stu_pub
demo04_stu_sub
demo05_turtle_circle_pub
demo06_turtle_pose_sub
demo07_turtle_control
demo08_hello_qt
demo09_sys_status_display_sub
  DESTINATION lib/${PROJECT_NAME})


if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
